<?php
/**
 * LG
 */
namespace Home\Model;
use Think\Model;
header("Content-type:text/html;charset=utf-8");
class UserModel extends Model{
    protected $_validate = array(
        array('username','require','账号不能为空！',1), //默认情况下用正则进行验证
        array('password','require','密码不能为空！',1)
    );

    public function getUsername(){
        $username = $this->where('username="'.$this->username.'"')
            ->field('username,id')->select();
        if($username == null){
            $AdminUser = D('Admin');
            $adminuser = $AdminUser->where('username="'.$this->username.'"')
                ->field('username,id')->select();
            return $adminuser;
        }else{
            return $username;
        }
    }
    public function getPassword(){
        $password = $this->where('username="'.$this->username.'"')->getField('password');
        if($password == null){
            $AdminPassword = D('Admin');
            $adminpassword = $AdminPassword->where('username="'.$this->username.'"')
                ->getField('password');
            if($adminpassword == $this->password){
                return true;
            }else{
                return false;
            }
        }else{
            if($password == $this->password){
                return true;
            }else{
                return false;
            }
        }
    }
    public function checkUser(){
        $username = cookie('username');
        $checkUser = $this->where('username="'.$username.'"')
            ->field('username')->select();
        return $checkUser;
    }
}
?>